package com.unism.base.util;

import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.message.GZipEncoder;
import org.glassfish.jersey.message.filtering.EntityFilteringFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.filter.EncodingFilter;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;

import com.unism.common.rest.errorhandling.AppExceptionMapper;
import com.unism.common.rest.errorhandling.CustomReasonPhraseExceptionMapper;
import com.unism.common.rest.errorhandling.GenericExceptionMapper;
import com.unism.common.rest.errorhandling.NotFoundExceptionMapper;
import com.unism.common.rest.errorhandling.ParamExceptionMapper;
import com.unism.common.rest.filters.CORSResponseFilter;
import com.unism.common.rest.filters.LoggingResponseFilter;
import com.unism.common.rest.filters.ParamFilter;

/**
 * Registers the components to be used by the JAX-RS application
 * 
 * @author ama
 * 
 */
public class BaseJaxRsApplication extends ResourceConfig {

	/**
	 * Register JAX-RS application components.
	 */
	public BaseJaxRsApplication() {
		
        packages("com.unism");
        
//		// register application resources
//		register(UserResource.class);
//
//		// register filters
		register(RequestContextFilter.class);
		register(LoggingResponseFilter.class);
		register(CORSResponseFilter.class);
		register(ParamFilter.class);
//
//		// register exception tappers
		register(GenericExceptionMapper.class);
		register(AppExceptionMapper.class);
		register(CustomReasonPhraseExceptionMapper.class);
		register(NotFoundExceptionMapper.class);
		register(ParamExceptionMapper.class);
		
//		
//		// register features
		register(MultiPartFeature.class);
		register(JacksonFeature.class);
		register(EntityFilteringFeature.class);
		EncodingFilter.enableFor(this, GZipEncoder.class);		
//		
//		property(EntityFilteringFeature.ENTITY_FILTERING_SCOPE, new Annotation[] {UserDetailedView.Factory.get()});
	}
}
